package com.it.homework;

import java.util.concurrent.*;

/**
 * @author げっしょく
 * @date 2021/8/7
 */
public class Test6 {
    public static void main(String[] args) {
        //6. 编写线程池两种实现方式（1. 使用工具类， 2. 自己new
        //month1();
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2,4,
                2, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        Runnable r = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "在运行");
            }
        };
        tpe.submit(r);
        tpe.submit(r);
        tpe.submit(r);
        tpe.submit(r);
        tpe.submit(r);
        tpe.shutdown();

    }

    private static void month1() {
        ExecutorService es = Executors.newCachedThreadPool();
        Runnable r = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "在运行");
            }
        };
        es.submit(r);
        es.submit(r);
        es.submit(r);
        es.shutdown();
    }
}
